#include <ctime>
#include <iostream>
#include <fstream>

using namespace std;

void bubbleSort(int a[], int b) {
	while(b--) 	{
		bool swapped = false;

		for(int i = 0; i < b; i++) {
			if(a[i] > a[i + 1]){
				swap(a[i], a[i + 1]);
				swapped = true;
			}
		}

		if(swapped == false) break;
	}
}

void read_from_file(const char *filename, int c[], int d) {
    ifstream e(filename);

    for(int i=0; i < d; i++)
        e >> c[i];
}

int main()
{
    #define LEN 5000
    int c[LEN];

    read_from_file("m1_sorted.txt",c,LEN);
    unsigned int start =  clock();
    bubbleSort(c,LEN);
    unsigned int finish = clock();
    unsigned int work = finish - start;
    cout<<"m1_sorted " << work << " milliseconds \n";

    read_from_file("m2_reverse.txt",c,LEN);
    start =  clock();
    bubbleSort(c,LEN);
    finish = clock();
    work = finish - start;
    cout<<"m2_reverse " << work << " milliseconds \n";

    read_from_file("m3_shuffle.txt",c,LEN);
    start =  clock();
    bubbleSort(c,LEN);
    finish = clock();
    work = finish - start;
    cout<<"m3_shuffle " << work << " milliseconds \n";

    return 0;
}
